//
//  YTBreakRecordsViewController.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/5/18.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTBreakRecordsViewController.h"
#import <DZNEmptyDataSet/UIScrollView+EmptyDataSet.h>
#import <YYWebImage/YYWebImage.h>
#import "YTBreakRecordViewCell.h"
#import "YTUserProfileServices.h"
#import "YTDriverBreakModel.h"

@interface YTBreakRecordsViewController ()<UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@property (weak, nonatomic) IBOutlet UILabel *normalText;
@property (weak, nonatomic) IBOutlet UILabel *specialText;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (copy, nonatomic) NSArray<YTDriverBreakModel *> *dataArray;
@end

@implementation YTBreakRecordsViewController

- (void)initialize {
    _tableView.rowHeight = 60;
    _tableView.tableFooterView = [UIView new];
    _dataArray = [NSArray array];
    [[YTUserProfileServices driverBreakRecoder] subscribeNext:^(NSDictionary *response) {
        NSDictionary *dict = response[@"responseData"];
        self.normalText.text = dict[@"normalMisdeedTimes"];
        self.specialText.text = dict[@"seriousMisdeedTimes"];
        self.dataArray = [NSArray yy_modelArrayWithClass:[YTDriverBreakModel class] json:dict[@"misdeedList"]];
        [self.tableView reloadData];
    }];
}

#pragma mark - UITableViewDataSource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YTBreakRecordViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YTBreakRecord" forIndexPath:indexPath];
    cell.model = _dataArray[indexPath.row];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

#pragma mark - DZNEmptyDataSetSource

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *text = @"暂无记录";
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:17.0f],
                                 NSForegroundColorAttributeName: kGrayColor};
    
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIImage imageNamed:@"public_norecord"];
}

@end
